package com.springcloud.hysitrix.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.springcloud.hysitrix.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * Title: PaymentHystrixController
 * Description: TODO
 *
 * @author gejx
 * @version V1.0
 * @date 2021-12-29
 */
@RestController
@Slf4j
//@DefaultProperties
public class PaymentHystrixController {
    @Resource
    private PaymentService paymentService;

    @GetMapping("/payment/get/ok/{id}")
    public String paymentInfo_ok(@PathVariable("id") Integer id){

        return paymentService.paymentInfo_ok(id);
    }
    //解决服务段的问题
    @GetMapping("/payment/get/timeout/{id}")
    @HystrixCommand(fallbackMethod = "paymentInfo_TimeoutHandler",//兜底方法
            commandProperties = {
                    @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",
                            value="3000")//设置3三秒的服务时间
            })
    public String paymentInfo_Timeout(@PathVariable("id") Integer id){
//        int age=10/0;
        return paymentService.paymentInfo_Timeout(id);
    }
    public String paymentInfo_Default(){
        return "消费者80，对方服务繁忙请稍后重试o(╥﹏╥)o";
    }
    public String paymentInfo_TimeoutHandler(Integer id){
        return "消费者80，对方服务繁忙请稍后重试o(╥﹏╥)o";
    }
    public static String payment_Global_FallbackMethod()
    {
        return "Global异常处理信息，请稍后再试，/(ㄒoㄒ)/~~";
    }

}
